<?php
/**
 * 管理员账号插入实现类
 * User: wuz
 * Date: 2016/8/16
 * Time: 21:18
 */
$adminName       = $_POST['username'];
$adminPassword   = $_POST['password'];
$adminIp         = $_SERVER['REMOTE_ADDR']; //获取当前用户的IP
$adminEnrollDate = date('y-m-d h:i:s', time());
header("content-type:text/html;charset=utf-8");
include "../Mysql/MySqlClass.php";
$MySQL = new Ycf\Lession\MySqlClass\MySqlClass('jinling_company', 'root', '123456');
if (empty($_POST['username']) || empty($_POST['password'])) {
    echo "用户名密码不能为空";
} else {
    $selectUserName = array('adminName' => $_POST['username'],
    );
    $userName = $MySQL->select("admin", $selectUserName); //通过用户名和密码查询数据库
    if (count($userName) != 0) {
        echo "用户已存在";
    } else {

        $insert = array(
            'adminName'       => $adminName,
            'adminPassword'   => $adminPassword,
            'adminEnrollDate' => $adminEnrollDate,
            'adminState'      => '1',
            'adminEnrollIp'   => $adminIp,
        );
        $MySQL->insert("admin", $insert);
        header("Location: ../userList.php"); //跳转要注意路径
    }
}
